package com.e7.util;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;

public class Uploader {
	/**
	 * 
	 * @param file
	 *            the post image
	 * @param realpath 
	 * @param fileName 
	 * @param fileName
	 *            the saved file name
	 * @return
	 */
	public String save(File file, String realpath, String fileName) {
		File saveFile = new File(new File(realpath), fileName);
		try {
			if (!saveFile.getParentFile().exists())
				saveFile.getParentFile().mkdirs();
			FileUtils.copyFile(file, saveFile);
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
		return saveFile.getAbsolutePath();
	}
}
